home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / OrganicFrameBorder.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  163 lines

  1. /*
  2.  * @(#)OrganicFrameBorder.java    1.4 98/02/02
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing.plaf.organic;
  22.  
  23. import com.sun.java.swing.*;
  24. import com.sun.java.swing.border.*;
  25. import com.sun.java.swing.plaf.*;
  26. import java.awt.*;
  27.  
  28. /**
  29.  * Object capable of rendering a line border of arbitrary thickness
  30.  * using four seperate colors.
  31.  * <p>
  32.  * Warning: serialized objects of this class will not be compatible with
  33.  * future swing releases.  The current serialization support is appropriate
  34.  * for short term storage or RMI between Swing1.0 applications.  It will
  35.  * not be possible to load serialized Swing1.0 objects with future releases
  36.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  37.  * baseline for the serialized form of Swing objects.
  38.  *
  39.  * @version 1.4 02/02/98
  40.  * @author Michael C. Albers
  41.  */
  42. public class OrganicFrameBorder extends AbstractBorder {
  43.  
  44.   private          JInternalFrame jif = null;
  45.  
  46.   protected static int thickness = 2;
  47.   protected static Color leftColor;
  48.   protected static Color rightColor;
  49.   protected static Color topColor;
  50.   protected static Color bottomColor;
  51.   protected static Color inactiveColor;
  52.   
  53.   
  54.   public OrganicFrameBorder(Color lcolor, Color rcolor, 
  55.             Color tcolor, Color bcolor, 
  56.             Color iColor, int thickness)  {
  57.     leftColor   = lcolor;
  58.     rightColor  = rcolor;
  59.     topColor    = tcolor;
  60.     bottomColor = bcolor;
  61.     inactiveColor = iColor;
  62.     this.thickness = thickness;
  63.   }
  64.  
  65.   public void paintBorder(Component c, Graphics g, int x, int y,
  66.               int width, int height) {
  67.     Color oldColor = g.getColor();
  68.     boolean isSelected = true;
  69.  
  70.     if (c instanceof JInternalFrame) {
  71.       jif = (JInternalFrame)c;
  72.       isSelected = jif.isSelected();
  73.     }
  74.  
  75.     for(int i = 0; i < thickness; i++)  {
  76.       // Draw top lines (upper left to upper right)
  77.       if (isSelected) {
  78.     g.setColor(topColor);
  79.       } else {
  80.     g.setColor(inactiveColor);
  81.       }
  82.       g.drawLine(x, y+i, x+width-thickness-1, y+i);
  83.       // Draw right lines (upper right to lower right)
  84.       if (isSelected) {
  85.     g.setColor(rightColor);
  86.       } else {
  87.     g.setColor(inactiveColor);
  88.       }
  89.       g.drawLine(x+width-i-1, y, x+width-i-1, y+height-thickness-1);
  90.       // Draw bottom lines (bottom left to botom right)
  91.       if (isSelected) {
  92.     g.setColor(bottomColor);
  93.       } else {
  94.     g.setColor(inactiveColor);
  95.       }
  96.       g.drawLine(x+thickness, y+height-i-1, x+width-1, y+height-i-1);
  97.       // Draw left lines (upper left to lower left)
  98.       if (isSelected) {
  99.     g.setColor(leftColor);
  100.       } else {
  101.     g.setColor(inactiveColor);
  102.       }
  103.       g.drawLine(x+i, y+thickness, x+i, y+height-1);
  104.     }
  105.     g.setColor(oldColor);
  106.   }
  107.   
  108.   // Private method used to determine which colors to use for the 
  109.   //  multicolor or unicolor border depending on whether the window
  110.   //  is selected or not.
  111.   private void setBorderColors(boolean isSelected) {
  112.     
  113.   }
  114.  
  115.   /**
  116.    * Returns the insets of the border.
  117.    * @param c the component for which this border insets value applies
  118.    */
  119.   public Insets getBorderInsets(Component c) {
  120.     return new Insets(thickness, thickness, thickness, thickness);
  121.   }
  122.  
  123.   /**
  124.    * Returns the top-edge color of the border.
  125.    */
  126.   public Color getTopColor()     {
  127.     return topColor;
  128.   }
  129.  
  130.   /**
  131.    * Returns the bottom-edge color of the border.
  132.    */
  133.   public Color getBottomColor()     {
  134.     return bottomColor;
  135.   }
  136.  
  137.   /**
  138.    * Returns the right-edge color of the border.
  139.    */
  140.   public Color getRightColor()     {
  141.     return rightColor;
  142.   }
  143.  
  144.   /**
  145.    * Returns the left-edge color of the border.
  146.    */
  147.   public Color getLeftColor()     {
  148.     return leftColor;
  149.   }
  150.   
  151.   /**
  152.    * Returns the thickness of the border.
  153.    */
  154.   public int getThickness()       {
  155.     return thickness;
  156.   }
  157.  
  158.   /**
  159.    * Returns whether or not the border is opaque.
  160.    */
  161.   public boolean isBorderOpaque() { return true; }
  162. }
  163.